//
//  TSLabelCollectionViewCell.swift
//  Picture
//
//  Created by 王磊 on 28/04/2017.
//  Copyright © 2017 ThreeStone. All rights reserved.
//

import UIKit

class TSLabelCollectionViewCell: UICollectionViewCell {
    
    internal var indexPath: NSIndexPath?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        commitInitOwnProperties()
        
        ts_configOwnSubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private var textLabel: UILabel = UILabel()
}

extension TSLabelCollectionViewCell {
    
    internal func updateData(data: AnyObject) {
        
        let labelBean = data as! TSLabelBean
        
        textLabel.text = labelBean.title
        
        selected(labelBean.isSelected)
    }
}

extension TSLabelCollectionViewCell {
    
    
    
}
extension TSLabelCollectionViewCell {
    internal func commitInitOwnProperties() {
        
        backgroundColor = UIColor.clearColor()
    }
    
    internal func ts_configOwnSubviews() {
        
        contentView.addSubview(textLabel)
        
        textLabel.layer.cornerRadius = 5
        
        textLabel.layer.borderWidth = 0.5
        
        textLabel.textAlignment =  .Center
        
        textLabel.textColor = Label_DeSelected_Color
        
        textLabel.layer.borderColor = Label_DeSelected_Color.CGColor
    }
}

extension TSLabelCollectionViewCell {
    
    internal func selected(isSelected: Bool) {
        
        textLabel.layer.cornerRadius = 5
        
        textLabel.layer.borderWidth = 0.5
        
        textLabel.textAlignment =  .Center
        
        textLabel.layer.borderColor = isSelected ? Label_Selected_Color.CGColor : Label_DeSelected_Color.CGColor
        
        textLabel.textColor = isSelected ? Label_Selected_Color : Label_DeSelected_Color
    }
}

extension TSLabelCollectionViewCell {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        textLabel.frame = bounds
        
    }
}
